package test;

public class test5 {
    public static void main(String[] args) {
        //静态二维数组
        int[][] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}};
        //动态二维数组
        int[][] arr1 = new int[2][8];//实际上是开辟两个一维数组，在一维数组的基础上开辟8个元素的空间
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr1[i].length; j++) {
                System.out.print(arr1[i][j] + " ");
            }
            System.out.println();
        }
        int[] arr3 = {1, 2, 3};
        int[] arr4 = {4, 5, 6};
        arr1[0] = arr3;
        arr1[1] = arr4;
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr1[i].length; j++) {
                System.out.print(arr1[i][j] + " ");
            }
            System.out.println();
        }
        //遍历二维数组
        for (int i = 0; i < arr.length; i++)//遍历每一行
        {
            for (int j = 0; j < arr[i].length; j++)//遍历一行里面的元素
            {
                System.out.print(arr[i][j] + " ");
            }
            //当打印完一行后换行便于阅读
            System.out.println();
        }
    }

    public void printArr(int[][] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
}
